const { Pool } = require('pg');

const pool = new Pool({
  host: 'localhost',
  port: 5432,
  database: 'aide',
  user: 'postgres',
  password: 'unidt@123',
});

(async () => {
  const client = await pool.connect();
  try {
    console.log('🔍 检查due_date字段类型...');
    
    const result = await client.query(`
      SELECT data_type 
      FROM information_schema.columns 
      WHERE table_name = 'tasks' 
        AND column_name = 'due_date' 
        AND table_schema = 'public'
    `);
    
    if (result.rows.length > 0) {
      console.log('✅ due_date字段类型:', result.rows[0].data_type);
      
      if (result.rows[0].data_type === 'text') {
        console.log('⚠️ 发现问题：due_date字段是text类型，这会触发数据清理！');
        console.log('💡 解决方案：需要修复数据库初始化脚本的字段类型检查逻辑');
      } else {
        console.log('✅ due_date字段类型正确，不会触发数据清理');
      }
    } else {
      console.log('❌ due_date字段不存在');
    }
    
    // 检查是否有任务数据
    const taskCount = await client.query('SELECT COUNT(*) FROM tasks');
    console.log(`📊 当前任务数量: ${taskCount.rows[0].count}`);
    
  } catch (error) {
    console.error('❌ 检查失败:', error.message);
  } finally {
    client.release();
    process.exit(0);
  }
})();
